<template>
  <div class="login-panel">
    <h2 class="title">后台管理系统</h2>
    <el-tabs type="border-card" class="demo-tabs" stretch v-model="currentTab">
      <el-tab-pane name="account">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon><Avatar /></el-icon>
            <span>账号登录</span>
          </span>
        </template>
        <LoginAccount ref="accountRef"></LoginAccount>
      </el-tab-pane>
      <el-tab-pane name="phone">
        <template #label>
          <span class="custom-tabs-label">
            <el-icon><PhoneFilled /></el-icon>
            <span>手机登录</span>
          </span>
        </template>
        <LoginPhone ref="phoneRef"></LoginPhone>
      </el-tab-pane>
    </el-tabs>
    <div class="account-control">
      <el-checkbox type="primary" v-model="iskeepPassword"
        >记住密码</el-checkbox
      >
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button class="login-btn" type="primary" @click="handlerLoginClick"
      >登录</el-button
    >
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from "vue";
import { Calendar, Avatar, PhoneFilled } from "@element-plus/icons-vue";
import LoginAccount from "./login-account.vue";
import LoginPhone from "./login-phone.vue";
export default defineComponent({
  components: {
    Calendar,
    Avatar,
    PhoneFilled,
    LoginAccount,
    LoginPhone,
  },
  setup() {
    const iskeepPassword = ref(false);
    const accountRef = ref<InstanceType<typeof LoginAccount>>(); //获取组件对象的类型
    const phoneRef = ref<InstanceType<typeof LoginPhone>>();
    const currentTab = ref<string>("account");
    const handlerLoginClick = () => {
      if (currentTab.value == "account") {
        //执行组件login-account中的函数
        accountRef.value?.loginAction(iskeepPassword.value);
      } else {
        phoneRef.value?.loginAction();
      }
    };
    return {
      iskeepPassword,
      accountRef,
      phoneRef,
      currentTab,
      handlerLoginClick,
    };
  },
});
</script>

<style scoped lang="less">
.login-panel {
  width: 320px;
  margin-bottom: 150px;
  .title {
    text-align: center;
  }
  .account-control {
    display: flex;
    justify-content: space-between;
  }
  .login-btn {
    margin-top: 10px;
    width: 100%;
  }
}
</style>
